<?php

    $pageindex = 4;
    $pacientcode = isset($_GET['code'])?$_GET['code']:"";
    $patientid = isset($_GET['patientid'])?$_GET['patientid']:"";
    $postid = isset($_GET['speccode'])?$_GET['speccode']:"";
    $prevpage = "page3.php";
    $nextpage = "";
    $errorpage = $prevpage;

    if(isset($_REQUEST['okremotedirection']))
    {

        ?>
        <p>
        <a href="print_preview.php?okremotedirection=<?php echo $_REQUEST['okremotedirection'];?>">Печатная форма</a>
        <br /><a href="/">Кабинет</a></p>
        </p>
        <?php
    }
    elseif(isset($_SESSION['form']) && isset($_REQUEST['tickets_ids']))
    {

        require_once(dirname(__FILE__).'/record.inc');
        $corrupted_record = in_array(1, $record->items()) || in_array(2, $record->items()); 
        if($corrupted_record === false)
        {
            ?><p>Запись проведена успешно.</p>
            <a href="index.php">Записать следующего пациента</a>
            <?php
            $_SESSION['form'] = null;
            header("Location: print_preview.php?okremotedirection=".$record->RemoteDirectionGuid);
            exit;
        }
        else
        {
            $_SESSION['recordresult'] = $record->items();
            header("Location: $prevpage");
            exit;
            ?><p>Ошибки.</p><?php
        }
    }
	else
	{
		header("Location: index.php");
		exit;
	}

    $mikron->Page->EndBody();

?>